/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: Dec 31, 2009
 * Time: 10:44:21 AM
 * To change this template use File | Settings | File Templates.
 */
import java.util.*;
import org.jdom.Element;


class Select
{

    Select(Element element, Schema schema)
    {
        fields = new ArrayList();
        Iterator iterator = element.getChildren().iterator();
        do
        {
            if(!iterator.hasNext())
                break;
            Element element1 = (Element)iterator.next();
            if(Schema.isDSDElement(element1))
                if(element1.getName().equals("attributefield"))
                    fields.add(new AttributeField(element1, schema));
                else
                if(element1.getName().equals("chardatafield"))
                    fields.add(new ChardataField(element1, schema));
                else
                    exp = Boolexp.parse(element1, schema);
        } while(true);
        if(exp == null)
            throw new InternalSchemaErrorException();
        else
            return;
    }

    Element toXML(Context context)
    {
        Element element = new Element("select", "http://www.brics.dk/DSD/2.0");
        element.addContent(exp.toXML(context));
        for(Iterator iterator = fields.iterator(); iterator.hasNext(); element.addContent(((Field)iterator.next()).toXML(context)));
        return element;
    }

    Boolexp exp;
    List fields;
}

